﻿#include "QCLabel.h"

#include "../../Tools/clock.h"

#include <QPainter>
#include <QStyleOption>

QCLabel::QCLabel(QWidget *parent) :
    QLabel(parent)
{
	m_lastPressTimestamp = 0;

    setMouseTracking(false);
}

QCLabel::~QCLabel()
{

}

// void QCLabel::paintEvent(QPaintEvent *event)
// {
// 	QStyleOption opt;
// 	opt.initFrom(this);
// 	QPainter p(this);
// 	style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
// 	QWidget::paintEvent(event);
// }


void QCLabel::mouseReleaseEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton){

		long long timestamp = Clock::milliseconds_now();
		if (timestamp - m_lastPressTimestamp < 300){
			emit dbclicked();
		}
		else{
			emit clicked();
		}

		m_lastPressTimestamp = timestamp;
    }
}

void QCLabel::enterEvent(QEvent *)
{
    emit mouseOn();
}

void QCLabel::leaveEvent(QEvent* e)
{
    emit mouseLeave();
}
